#include<cstdio>//BAONI
#include<cstring>
#include<algorithm>
using namespace std;
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int n,m,s,cnt;
struct node{
	int v,next;
}edge[1000010];
int head[500010];
int F[21][500010];
int Deep[500010];

void add_edge(int x,int y)
{
	edge[++cnt].v=y;
	edge[cnt].next=head[x];
	head[x]=cnt;
	return ;
}

void DFS(int x,int fa)
{
	F[0][x]=fa;
	Deep[x]=Deep[fa]+1;
	for(int i=head[x];~i;i=edge[i].next)
	{
		if(edge[i].v==fa)continue;
		DFS(edge[i].v,x);
	}
	return ;
}

void init()
{
	for(int i=1;i<=20;++i)
		for(int j=1;j<=n;++j)
			F[i][j]=F[i-1][F[i-1][j]];
	return ;
}

int LCA(int x,int y)
{
	if(Deep[x]>Deep[y])swap(x,y);
	for(int i=20;~i;i--)
	{
		if(Deep[x]<=Deep[F[i][y]])
			y=F[i][y];
	}
	if(x==y)return x;
	for(int i=20;~i;i--)
	{
		if(F[i][x]!=F[i][y])
		{
			x=F[i][x];
			y=F[i][y];
		}
	}
	return F[0][x];
}

int main()
{
	//freopen("in","r",stdin);
	memset(head,0xff,sizeof(head));
	int a,b;
	read(n);read(m);read(s);

	for(int i=1;i<=n-1;++i)
	{
		read(a);read(b);
		add_edge(a,b);
		add_edge(b,a);
	}

	DFS(s,s);

	init();

	for(int i=1;i<=m;++i)
	{
		read(a);read(b);
		printf("%d\n",LCA(a,b));
	}

	//fclose(stdin);
	return 0;
}